package com.coolingme.genericity;

/**
 * 测试泛型类
 *
 * @author wangyue
 * @date 2019/4/4 10:28
 */
public class GTest {

    public static void main(String[] args) {
        //基础类
        GInteger integer = new GInteger(23);
        integer.hello();
        System.out.println(integer);

        GString string = new GString("wangyue");
        string.hello();
        System.out.println(string);

        System.out.println("========================");

        //Object类，可以转成别的类型
        GObject oInteger = new GObject(500);//向上转型
        oInteger.hello();
        int age = (Integer) oInteger.getObject();//向下转型
        System.out.println("age:" + age);


        GObject oString = new GObject("Wy");//向上转型
        oString.hello();
        String name = (String) oString.getObject();//向下转型
        System.out.println("name:" + name);

        System.out.println("========================");

        // 泛型，创建时给定类型，不需要再转型
        Genericity<Integer> tInteger = new Genericity<Integer>(365);
        tInteger.hello();
        Integer tAge = tInteger.getT();
        System.out.println("tAge:" + tAge);

        Genericity<String> tString = new Genericity<String>("World");
        tString.hello();
        String tName = tString.getT();
        System.out.println("tName:" + tName);

    }
}
